import pygame

# 初始化 Pygame
pygame.init()

# 设置窗口大小
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Pygame Text Example")

# 加载字体
font = pygame.font.SysFont(None, 36)

# 渲染文字
text_surface = font.render("Hello, Pygame!", True, (255, 255, 255))

# 获取文字矩形并居中显示
text_rect = text_surface.get_rect(center=(screen.get_width() / 2, screen.get_height() / 2))

# 主循环
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # 清除屏幕并绘制文字
    screen.fill((0, 0, 0))
    screen.blit(text_surface, text_rect)

    # 更新显示
    pygame.display.flip()

# 退出 Pygame
pygame.quit()